package tunafish2k.rpgex.renderers;

import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory.Context;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import tunafish2k.rpgex.entities.StoneDartProjectile;
import tunafish2k.rpgex.registries.RendererRegistry;

public class StoneDartProjectileRenderer extends EntityRenderer<StoneDartProjectile> {
    public final StoneDartProjectileModel model;
    public static final Identifier TEXTURE = Identifier.ofVanilla("textures/block/stone.png");

    public StoneDartProjectileRenderer(Context context) {
        super(context);
        this.model = new StoneDartProjectileModel(context.getPart(RendererRegistry.MODEL_STONE_DART_LAYER));
    }

    @Override
    public Identifier getTexture(StoneDartProjectile entity) {
        return TEXTURE;
    }

    @Override
    public void render(StoneDartProjectile entity, float f, float g, MatrixStack matrixStack,
            VertexConsumerProvider vertexConsumerProvider, int i) {
        matrixStack.push();
        matrixStack.scale(0.5f, 0.5f, 0.5f);
        /**
         * matrixStack.multiply(RotationAxis.POSITIVE_X
         * .rotationDegrees(MathHelper.lerp(g, entity.prevPitch, entity.getPitch()) -
         * 90.0F));
         * matrixStack
         * .multiply(RotationAxis.POSITIVE_Y.rotationDegrees(MathHelper.lerp(g,
         * entity.prevYaw, entity.getYaw()) + 90.0F));
         */
        matrixStack.multiply(RotationAxis.POSITIVE_Y
                .rotationDegrees(MathHelper.lerp(g, entity.prevYaw, entity.getYaw()) - 90.0F));
        matrixStack.multiply(RotationAxis.POSITIVE_Z
                .rotationDegrees(MathHelper.lerp(g, entity.prevPitch, entity.getPitch()) + 90.0F));
        this.model.render(matrixStack, vertexConsumerProvider.getBuffer(this.model.getLayer(TEXTURE)), i,
                OverlayTexture.DEFAULT_UV);
        matrixStack.pop();
        super.render(entity, f, g, matrixStack, vertexConsumerProvider, i);
    }
}
